const express = require('express');
const connection = require("../db/sql");
const {selectUser, addUser, deleteUser, modifyUser, login} = require("../services/user");
const {verify} = require("jsonwebtoken");

const router = express.Router();

/* GET users listing. */
//所有用户
router.get('/users', async function (req, res) {
    console.log(645)
    // const authHeader = req.headers['authorization'];
    // const token = authHeader && authHeader.split(' ')[1];
    // let role = ''
    // verify(token, 'mysecret', (err, user) => {
    //     if (err) {
    //         return 0
    //     }
    //     // console.log(user, '7768')
    //     role = user.role
    //
    // });
    await selectUser(req.query, res, req.user.role)
})

// router.get('/user/selectUserById',function (req, res){
//   selectUserById(req.query,res)
// })
/**
 * 添加用户
 */
router.post('/users', function (req, res) {
    // console.log(req.body,'77')
    addUser(req.body, res)
})
router.delete('/users', function (req, res) {
    // console.log(req.body.userId,'不打卡点快了')
    deleteUser(req.query, res)
})
router.put('/users', function (req, res) {
    // console.log(req.body.userId,'不打卡点快了')
    modifyUser(req.body, res)
})
router.post('/login', async (req, res) => {
    // console.log(req.body, '三点')
    await login(req.body, res)
})
module.exports = router;
